const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('private_messages', {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      primaryKey: true,
      comment: "私信主键ID"
    },
    sender_id: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      comment: "发送者用户ID",
      references: {
        model: 'users', // 引用的表名
        key: 'id'       // 引用的字段名
      }
    },
    receiver_id: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      comment: "接收者用户ID",
      references: {
        model: 'users', // 引用的表名
        key: 'id'       // 引用的字段名
      }
    },
    message: {
      type: DataTypes.TEXT,
      allowNull: false,
      comment: "私信内容"
    },
    sent_at: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
      comment: "私信发送时间"
    },
    read_at: {
      type: DataTypes.DATE,
      allowNull: true,
      comment: "私信阅读时间"
    }
  }, {
    tableName: 'private_messages',
    timestamps: false, // 如果不希望Sequelize管理时间戳字段，可以设置为false
    comment: "用户私信表"
  });
};
